package ml.uuku.oschub.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.PagerTabStrip;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import ml.uuku.oschub.R;
import ml.uuku.oschub.adpater.ViewPageFragmentAdapter;
import ml.uuku.oschub.ui.empty.EmptyLayout;
import ml.uuku.oschub.widget.PagerSlidingTabStrip;

/**
 * @author <a href=http://my.oschina.net/uuku>uuku</a>
 * @version V0.1
 */
public abstract class BaseViewPagerFragment extends BaseFragment {

    protected PagerSlidingTabStrip mTabStrip;
    protected ViewPager mViewPager;
    protected ViewPageFragmentAdapter mTabAdapter;
    protected EmptyLayout mErrorLayout;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.base_viewpage_fragment, null);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
    }

    @Override
    public void initView(View view) {

        mTabStrip = (PagerSlidingTabStrip) view.findViewById(R.id.pager_tabstrip);
        mViewPager = (ViewPager) view.findViewById(R.id.pager);
        mErrorLayout = (EmptyLayout) view.findViewById(R.id.error_layout);

        mTabAdapter = new ViewPageFragmentAdapter(getChildFragmentManager(), mTabStrip, mViewPager);

        setScreenPageLimit();
        onSetupTabAdapter(mTabAdapter);
    }

    protected void setScreenPageLimit() {
    }

    protected abstract void onSetupTabAdapter(ViewPageFragmentAdapter adapter);

    @Override
    public void initData() {

    }
}
